﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using Models.DataAccess;


namespace springProject.Models
{
    public class EditFolderModel
    {
        public Guid id { get; set; }
        public Guid? parentId { get; set; }

        [Display(Name = "Имя папки")]
        [RegularExpression(@"[A-Za-zА-Яа-я_\s-]*", ErrorMessage = "Вы используете запрещенные символы")]
        [StringLength(50, ErrorMessage = "Введите настоящее имя", MinimumLength = 1)]
        public string folderName { get; set; }

        public EditFolderModel(Folders folder)
        {
            this.id = folder.FolderId;
            this.parentId = folder.ParentId;            
            this.folderName = folder.FolderName;
        }

        public EditFolderModel()
        {

        }

        public Folders ToFolders()
        {
            return new Folders
            {
                FolderId = this.id,
                FolderName = this.folderName,
                ParentId = this.parentId
            };
        }

        public Folders ToFolders(Repository repository)
        {
            var folder = repository.GetById<Folders>(id);
            folder.FolderName = this.folderName;
            return folder;
        }
    }
}